﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Wicresoft.SMS.Adapter.Interface;
using ImApiDotNet;

namespace Wicresoft.SMS.Adapter.Imp
{
    public class XMImp : ISMSAdapter
    {
        APIClient client = new APIClient();
        public string Init(string conStr)
        {
            if (string.IsNullOrEmpty(conStr))
                return "ConStr Format Error.";
            string[] configs = conStr.Split(';');
            int retCode = client.init(configs[0], configs[1], configs[2], configs[3], configs[4]);
            return ConvertReturnCode(retCode);
        }

        public string SendInTimeSMS(string[] mobile, string content)
        {
            int retCode = client.sendSM(mobile,content,0,0);
            return ConvertReturnCode(retCode);
        }

        public void Dispose()
        {
            client.release();
        }


        public string ConvertReturnCode(int returnCode)
        {
            switch (returnCode)
            {
                case 0: return "IMAPI_SUCC : 操作成功";
                case -1: return "IMAPI_CONN_ERR : 连接数据库出错";
                case -2: return "IMAPI_CONN_CLOSE_ERR : 数据库关闭失败";
                case -3: return "IMAPI_INS_ERR : 数据库插入错误";
                case -4: return "IMAPI_DEL_ERR : 数据库删除错误";
                case -5: return "IMAPI_QUERY_ERR : 数据库查询错误";
                case -6: return "IMAPI_DATA_ERR : 参数错误";
                case -7: return "IMAPI_API_ERR : API编码非法";
                case -8: return "IMAPI_DATA_TOOLONG : 参数超长";
                case -9: return "IMAPI_INIT_ERR : 没有初始化或初始化失败";
                case -10: return "IMAPI_IFSTATUS_INVALID : API接口处于暂停（失效）状态";
                case -11: return "IMAPI_GATEWAY_CONN_ERR : 短信网关未连接";
                default: return "UN_KNOWN : 未知返回值";
            }

        }
    }


}
